import java.io.*;
import java.net.*;

public class TaanieliServer{
  public static void main(String[] arg) throws Exception{
  ServerSocket ss=new ServerSocket(3019);
  int nr=0;
  while(true){
	  Socket sc=ss.accept();
	  System.out.println(sc);
	  PrintWriter vorku=new PrintWriter(sc.getOutputStream(), true);
	  vorku.println("Taanieli programm ütleb "+nr+" tere");
	  vorku.println("Kes sa oled?");
	  BufferedReader br=new BufferedReader(new InputStreamReader(sc.getInputStream()));
	  String kirjeldus=br.readLine();
	  vorku.println("Ahoi, "+kirjeldus);
	  sc.close();
	  }
  }
}